﻿using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Model;
using YouHP.DALFactory;
using YouHP.Utility;

namespace YouHP.BLL
{
    public class GroupNewsBLL
    {
        #region Singleton
        static GroupNewsBLL _Instance;
        public static GroupNewsBLL Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new GroupNewsBLL();
                }
                return _Instance;
            }
        }
        #endregion

        #region basic operations
        public bool AddGroupNews(GroupNewsInfo info)
        {
            return DataAccess.GroupNewsDAL.AddGroupNews(info);
        }

        public bool UpdateGroupNews(GroupNewsInfo info)
        {
            return DataAccess.GroupNewsDAL.UpdateGroupNews(info);
        }

        public bool DeleteGroupNews(int[] ids)
        {
            return DataAccess.GroupNewsDAL.DeleteGroupNews(ids);
        }

        public bool DeleteGroupNews(int groupId, int[] ids)
        {
            //return DataAccess.GroupNewsDAL.DeleteGroupNews(ids);
            return true;
        }

#if GENDATA
        public GroupNewsInfo GetGroupNewsInfo(int id)
        {
            GroupNewsInfo info = new GroupNewsInfo();
            info.Id = id;
            info.Title = "新闻标题";
            info.Body = "新闻内容";
            info.UpdateTime = DateTime.Now;
            return info;
        }
#else
        public GroupNewsInfo GetGroupNewsInfo(int id)
        {
            return DataAccess.GroupNewsDAL.GetGroupNewsInfo(id);
        }
#endif
        #endregion

        #region GroupNewsComment

        public bool AddGroupNewsComment(NewsComment newsComment)
        {
            return DataAccess.GroupNewsCommentDAL.AddNewsComment(newsComment);
        }

        public NewsComment GetGroupNewsCommentByID(int id)
        {
            return DataAccess.GroupNewsCommentDAL.GetNewsComment(id);
        }

        public List<NewsComment> GetGroupNewsCommentList(int newsID)
        {
            return DataAccess.GroupNewsCommentDAL.GetNewsCommentList(newsID);
        }

        public bool UpdateGroupNewsComment(NewsComment newsComment)
        {
            return DataAccess.GroupNewsCommentDAL.UpdateNewsComment(newsComment);
        }

        public bool DeleteGroupNewsComment(int id)
        {
            return DataAccess.GroupNewsCommentDAL.DeleteNewsComment(id);
        }

        public int GetNewsCommentCount(int newsID)
        {
            return DataAccess.GroupNewsCommentDAL.GetNewsCommentCount(newsID);
        }


        #endregion

        #region list and search operations

#if GENDATA
        public List<GroupNewsInfo> GetGroupNewsList(int pageSize, int pageIndex, out int count)
        {
            count = 12;
            List<GroupNewsInfo> lst = new List<GroupNewsInfo>();
            for (int i = 1; i < 10; i++)
            {
                GroupNewsInfo info = GetGroupNewsInfo(i);
                lst.Add(info);
            }
            return lst;
        }
#else
        public List<GroupNewsInfo> GetGroupNewsList(int pageSize, int pageIndex, out int count)
        {
            return DataAccess.GroupNewsDAL.GetGroupNewsList(pageSize, pageIndex, out count);
        }
#endif

        //获得圈子新闻列表
        public List<GroupNewsInfo> GetGroupNewsList(int groupId, int pageSize, int pageIndex, out int count)
        {
            return DataAccess.GroupNewsDAL.GetGroupNewsByGroupId(pageSize, pageIndex, groupId, out count);
        }

        /*search for management*/
        public List<GroupNewsInfo> GetAllGroupNewsByName(string keyword)
        {
            int count = 0;
            return DataAccess.GroupNewsDAL.GetGroupNewsByName(Constants.maxPageSize, 1, keyword, out count);
        }

        public List<GroupNewsInfo> GetAllGroupNewsByGroupId(int groupId)
        {
            int count = 0;
            return DataAccess.GroupNewsDAL.GetGroupNewsByGroupId(Constants.maxPageSize, 1, groupId, out count);
        }

        public List<GroupNewsInfo> GetGroupNewsByGroupId(int pageSize, int pageIndex, int groupId, out int count)
        {
            return DataAccess.GroupNewsDAL.GetGroupNewsByGroupId(pageSize, pageIndex, groupId, out count);
        }
        #endregion

#if GENDATA
        public List<GroupNewsInfo> GetLattestNews(int gid, int n)
        {
            List<GroupNewsInfo> lst = new List<GroupNewsInfo>();
            for (int i = 1; i <= n; i++)
            {
                GroupNewsInfo info = new GroupNewsInfo();
                lst.Add(info);
                info.Id = i;
                info.Title = "新闻标题";
                info.Introduction = "关于糖尿病的讲座";
                info.UpdateTime = DateTime.Now.AddDays(-i);
            }
            return lst;
        }
#else
        public List<GroupNewsInfo> GetLattestNews(int gid, int n)
        {
            return DataAccess.GroupNewsDAL.GetLattestNews(gid, n);
        }
#endif
    }
}